import 'package:flutter/material.dart';
import 'package:robotcontrol/page/discovery/category_page.dart';
import 'package:robotcontrol/utils/tip_util.dart';
import 'package:robotcontrol/page/discovery/follow_page.dart';
import 'package:robotcontrol/widgets/appbar.dart';
import 'package:robotcontrol/widgets/tab_bar.dart';
const TAB_LABEL = ['关注', '分类', '专题', '资讯', '推荐'];
class DiscoveryPage extends StatefulWidget {
  @override
  _DiscoveryPageState createState() => _DiscoveryPageState();
}

class _DiscoveryPageState extends State<DiscoveryPage>
    with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  TabController _tabController;

  @override
  void initState() {
    super.initState();
    // vsync:ticker 驱动动画,每次屏幕刷新都会调用TickerCallback，
    _tabController = TabController(length: TAB_LABEL.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: appBar(
        TipUtil.discovery,
        showBack: false,
        bottom: tabBar(
          controller: _tabController,
          tabs:TAB_LABEL.map((String labl){
            return Tab(text: labl,);
          }).toList(),
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        // 与标签个数一致
        children: [
          FolloPage(),
          CategoryPage(),
          FolloPage(),
          FolloPage(),
          FolloPage(),
        ],
      ),
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
